home *** CD-ROM | disk | FTP | other *** search
- ;-------------------------dec8out routine begins--------------------------+
- ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
- ; page : 59
- ;
- ; NAME DEC8OUT
- ; ROUTINE FOR Conversion from 8-bit Binary to ASCII decimal
- ;
- ; FUNCTION: This routine accepts a 8-bit binary number in the DL register
- ; and converts it to ASCII decimal form which is sent to the std input
- ; device.
- ;
- ; INPUT: Upon entry an 8-bit binary number is in DL
- ; OUTPUT: A string of ASCII digits representing a decimal number is
- ; stored in a buffer called TBUFF and then sent out through the std output
- ; device.
- ; REGISTERS USED: No registers are modified. DL is used for input.
- ; SEGMENTS REFERENCED: DATAS is a data segment which contains TBUFF.
- ; ROUTINES CALLED: STDOUT
- ; SPECIAL NOTES: None
- ;
- ; ROUTINE TO CONVERT FROM INTERNAL 8-BIT BINARY TO ASCII DECIMAL.
- ;
- dec8out proc far
- ;
- push ds ; save registers
- push di
- push dx
- push cx
- push ax
- ;
- mov ax,datas ; point to the data segment
- mov ds,ax
- ;
- ; binary number is in DL
- ;
- ; Put the digits in a buffer
- ;
- mov cx,0 ; initialize a counter
- mov di,offset tbuff ; point to a buffer
- ;
- dec8out1:
- push cx ; save the count
- mov al,dl ; AX has the numerator
- mov ah,0 ; clear upper half
- mov cl,10 ; divisor of 10
- div cl ; divide
- mov dl,al ; get quotient
- mov al,ah ; get remainder
- ;
- add al,30h ; increase to ASCII
- mov [di],al ; put in tbuff
- inc di ; point to next byte
- ;
- pop cx ; restore count
- inc cx ; count the digit
- cmp dl,0 ; done ?
- jnz dec8out1
- ;
- ; dump tbuff out
- ;
- dec8out2
- dec di ; back up through the tbuff
- mov al,[di] ; get the byte from the tbuff
- call stdout ; send it
- loop dec8out2
- ;
- pop ax ; restore registers
- pop cx
- pop dx
- pop di
- pop ds
- ret ; return
- ;
- dec8out endp
- ;-------------------------dec8out routine ends---------------------------+